auto.waitFor();
var appName = "快手";
launchApp(appName);
sleep(3000);
// 等待控件出现
id("pendant_mask_bg").waitFor();
// 点击坐标位置
click(118, 691);
showAdv();

function showAdv() {
  // 领福利按钮
  className("android.widget.Button").text("领福利 赚更多").waitFor();
  var adv = className("android.widget.Button").text("领福利 赚更多").findOne();
  if (adv) {
    adv.click();
    sleep(2000);
    execTask();
  } else {
    back();
    showAdv();
  }
}
function execTask() {
  while (true) {
    textMatch("已成功领取").waitFor();
    var cglq = textMatch("已成功领取").findOne();
    if (cglq) {
      sleep(1500);
      click(411, 210);
      sleep(3000);
    }
    if (id("live_follow_text").exists()) {
      toast("找到了直播间");
      back();
      var fangqi = text("放弃奖励").findOne();
      fangqi.click();
      showAdv();
    } else {
      id("again_medium_icon_dialog_ensure_text").waitFor();
      var target = text("领取奖励").findOnce();
      if (target == null) {
        showAdv();
      }
      target.click();
      sleep(20000);
    }

    for (let i = 0; i <= 2; i++) {
        var fangqi = text("放弃奖励").findOne();
        if(fangqi){
            fangqi.click();
            sleep(2000);
        }
    }
  }
}
